home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / scheme / pcscheme / geneva / sources.exe / SOURCES / ASM / SCHEME.AS0 < prev    next >
Encoding:
Text File  |  1993-11-08  |  29.5 KB  |  1,015 lines

  1. ;* SCHEME.ASH
  2. %PUSHLCTL
  3. %NOLIST
  4. ;************************************************************************
  5. ;*                                    *
  6. ;*        PC Scheme/Geneva 4.00 Borland TASM code            *
  7. ;*                                    *
  8. ;* (c) 1985-1988 by Texas Instruments, Inc. See COPYRIGHT.TXT        *
  9. ;* (c) 1992 by L. Bartholdi & M. Vuilleumier, University of Geneva    *
  10. ;*                                    *
  11. ;*----------------------------------------------------------------------*
  12. ;*                                    *
  13. ;*        All scheme constants you dreamed of            *
  14. ;*                                    *
  15. ;*----------------------------------------------------------------------*
  16. ;*                                    *
  17. ;* Created by: John Jensen        Date: 1985            *
  18. ;* Revision history:                            *
  19. ;* - 10 Feb 87:    Modified Page 5 special symbols to reflect #T        *
  20. ;*             per the R^3 Report. (tc)                *
  21. ;* - 18 Jun 92:    Renaissance (Borland Compilers, ...)            *
  22. ;*                                    *
  23. ;*                    ``In nomine omnipotentii dei''    *
  24. ;************************************************************************
  25.  
  26. P8086
  27. P8087
  28. EMUL
  29.  
  30. ; Signal a debugging point when vm_debug enabled.
  31. MACRO    action    what
  32.     LOCAL    @@text, @@adr, @@skip
  33.     IFDEF    VMDEBUG
  34. Dataseg
  35. @@text    db    '&what', 0
  36. @@adr    dw    OFFSET    @@text
  37. Codeseg    
  38.     cmp    [vm_debug], 0
  39.     jz    @@skip
  40.     push    ax bx cx dx es
  41.     pushf
  42.     call    printf C, [@@adr]
  43.     popf
  44.     pop    es dx cx bx ax
  45. @@skip:
  46.     ENDIF
  47.     ENDM
  48.  
  49. ; Adjust page number prior to store into pointer
  50. MACRO    adjpage    reg
  51.     sal    reg, 1
  52.     ENDM    
  53.     
  54. ; Convert page number from physical representation to logical page
  55. MACRO    corpage reg
  56.     shr    reg, 1
  57.     ENDM    
  58.     
  59. ; Push the page number and displacement components of a Scheme
  60. ; pointer onto the runtime stack (parameter passing mechanism)
  61. MACRO    pushptr    addr
  62.     push    [(POINTER addr).disp]
  63.     mov    al, [(POINTER addr).page]
  64.     and    ax, PAGEMASK
  65.     push    ax
  66.     ENDM    
  67.     
  68. ; Pop the page number and displacement components of a Scheme
  69. ; pointer from the runtime stack and restore a memory location
  70. ; (parameter return mechanism)
  71. MACRO    popptr    addr
  72.     pop    ax
  73.     mov    [(POINTER addr).page], al
  74.     pop    [(POINTER addr).disp]
  75.     ENDM    
  76.  
  77. ; Save the registers in the macro's argument (a list) in the local
  78. ; stack in the variables "save_xx", where "xx" is the register name.
  79. MACRO    save    regs
  80.     IRP    rr, <regs>
  81.     mov    [save_&&rr], rr
  82.     ENDM    
  83.     ENDM    
  84.     
  85. ; Restore the registers in the macro's argument (a list) from the local
  86. ; stack in the variables "save_xx", where "xx" is the register name.
  87. MACRO    restore    regs
  88.     IRP    rr, <regs>
  89.     mov    rr, [save_&&rr]
  90.     ENDM
  91.     ENDM
  92.  
  93. MACRO    get1op    
  94.     seges    lodsb
  95.     ENDM
  96.  
  97. MACRO    get2op    
  98.     seges    lodsw
  99.     ENDM
  100.  
  101. BELL        EQU    07h        ; Standard ascii constants
  102. BACKSPACE    EQU    08h
  103. TAB        EQU    09h
  104. LF        EQU    0ah
  105. CR        EQU    0dh
  106. CTRL_Z        EQU    1ah
  107. ESCAPE        EQU    1bh
  108. SPACE        EQU    20h
  109. DEL        EQU    7fh    ; ctrl-backspaceh
  110.  
  111. ENTER_KEY    EQU    0d00h        ; Extended key codes
  112. HOME_KEY    EQU    4700h
  113. UP_KEY        EQU    4800h
  114. LEFT_KEY    EQU    4b00h
  115. RIGHT_KEY    EQU    4d00h
  116. END_KEY        EQU    4f00h
  117. DOWN_KEY    EQU    5000h
  118. INSERT_KEY    EQU    5200h
  119. DELETE_KEY    EQU    5300h
  120. CTRL_LEFT_KEY    EQU    7300h
  121. CTRL_RIGHT_KEY    EQU    7400h
  122. CTRL_END_KEY    EQU    7500h
  123. CTRL_HOME_KEY    EQU    7700h
  124. CTRL_DEL_KEY    EQU    9300h      ; exists since DOS 5.0 (or 4.0 ?)
  125.  
  126. MSDOS        =    21h        ; Most used interrupts
  127. IBM_CRT        =    10h
  128. EMMINT        =    67h
  129.  
  130. ; The following equates set the limits on the virtual memory (paging) system:
  131. MIN_PAGESIZE     =    0C00H        ; Minimum page size for conventional memory
  132. MAXEMS        =    NUMPAGES - PREALLOC - 8    ; guarantee we use some conventional mem.
  133. EMSSIZE        =    4000h
  134.  
  135. NUMPAGES     =    128         ; Total number of pages
  136. DEDPAGES     =    8         ; Number of dedicated pages
  137. PREALLOC     =    DEDPAGES+1     ; Pre-allocated pages
  138.     
  139. HT_SIZE        =    211         ; The oblist's hash table size
  140. STKSIZE        =    900         ; Length of Scheme's internal stack (bytes)
  141. NUM_REGS     =    64         ; Number of general regs in the Scheme VM
  142. SPECIALCHARS    =    8        ; special chars: NEWLINE, RUBOUT, ...
  143. GC_BIT        =    1 shl 0        ; bit #0 is used in all structures for GC
  144.  
  145. ; Page attribute bits
  146. ATOM        =    08000H         ; 1 = Atomic data
  147. LISTCELL    =    04000H        ; 1 = List (cons) cells
  148. FIXNUMS        =    02000H         ; 1 = 16-bit integer data
  149. FLONUMS        =    01000H         ; 1 = 32-bit floating point data
  150. BIGNUMS        =    00800H         ; 1 = big integer values
  151. SYMBOLS        =    00400H         ; 1 = symbols
  152. STRINGS        =    00200H         ; 1 = strings
  153. VECTORS        =    00100H         ; 1 = vector (array) storage
  154. NOMEMORY    =    00080H         ; 1 = no memory allocated
  155. READONLY    =    00040H         ; 1 = memory is read only (constant)
  156. CONTINU        =    00020H         ; 1 = continuation object
  157. CLOSURE        =    00010H         ; 1 = closure object
  158. I86CODE        =    00008H         ; 1 = inline 8086 code
  159. PORTS        =    00004H         ; 1 = I/O ports
  160. CODE        =    00002H         ; 1 = code block
  161. CHARS        =    00001H         ; 1 = characters
  162. NUMBERS        =    FIXNUMS+FLONUMS+BIGNUMS ; number (fixnums, flonums, bignums)
  163.     
  164. ; Data type equates (classes of data objects)
  165. NUMTYPES    =    15        ; Number of data types
  166. LISTTYPE    =    0
  167. FIXTYPE        =    2
  168. FLOTYPE        =    4
  169. BIGTYPE        =    6
  170. SYMBTYPE    =    8
  171. STRTYPE        =    10
  172. VECTTYPE    =    12
  173. CONTTYPE    =    14
  174. CLOSTYPE    =    16
  175. FREETYPE    =    18
  176. CODETYPE    =    20
  177. I86TYPE        =    22
  178. PORTTYPE    =    24
  179. CHARTYPE    =    26
  180. ENVTYPE        =    28
  181.     
  182. ; Special pre-allocated pages
  183. SPECCHAR    =    1
  184. SPECFREE    =    2
  185. SPECFIX        =    3
  186. SPECFLO        =    4
  187. SPECSYM        =    5
  188. SPECPOR        =    6
  189. SPECCODE    =    7
  190.     
  191. ; Predefined constants
  192. T_PAGE        =    SPECSYM     ; symbol 't' (representing true)
  193. T_DISP        =    0000H
  194. UN_PAGE        =    SPECSYM     ; symbol '#!unassigned' (unbound variable)
  195. UN_DISP        =    0009H
  196. NTN_PAGE    =    SPECSYM     ; symbol '#!not-a-number'
  197. NTN_DISP    =    001CH
  198. DIV0_PAGE    =    SPECSYM     ; symbol for divide by 0
  199. DIV0_DISP    =    001CH
  200. EOF_PAGE    =    SPECSYM     ; symbol for '#!EOF
  201. EOF_DISP    =    00031H
  202. NPR_PAGE    =    SPECSYM     ; symbol for '#!unprintable'
  203. NPR_DISP    =    003DH
  204.     
  205. NIL_PAGE    =    0         ; symbol 'nil' (representing itself)
  206. NIL_DISP    =    0
  207.     
  208. ; End of linked list indicator
  209. END_LIST    =    07FFFH
  210.     
  211. ; Numeric operator sub-opcodes
  212. ADD_OP        =    0         ; add
  213. SUB_OP        =    1         ; subtract
  214. MUL_OP        =    2         ; multiply
  215. DIV_OP        =    3         ; divide
  216. REM_OP        =    4         ; remainder
  217. AND_OP        =    5         ; bitwise-and
  218. OR_OP        =    6         ; bitwise-or
  219. MINUS_OP    =    7         ; minus
  220. EQ_OP        =    8         ; = (equal comparison)
  221. NE_OP        =    9         ; <> (not equal comparison)
  222. LT_OP        =    10         ; < (less than comparison)
  223. GT_OP        =    11         ; > (greater than comparison)
  224. LE_OP        =    12         ; <= (less than or equal comparison)
  225. GE_OP        =    13         ; >= (greater than or equal comparison)
  226. ABS_OP        =    14         ; absolute value
  227. QUOT_OP        =    15         ; quotient (integers)
  228. ZERO_OP        =    21         ; zero?
  229. POS_OP        =    22         ; positive?
  230. NEG_OP        =    23         ; negative?
  231. XOR_OP        =    24         ; bitwise-xor
  232. DIVIDE_OP    =    25        ; divide (integers)
  233. MOD_OP        =    26        ; modulo
  234.  
  235. RV_PROCEED    =    0
  236. RV_HALT        =    1
  237. RV_SDEBUG    =    2
  238. RV_CLOBBERED    =    3
  239.     
  240. ; Numeric Error Codes
  241. REF_GLOBAL_ERROR    =    1     ; reference of unbound global variable
  242. SET_GLOBAL_ERROR    =    2    ; SET! error-- global not defined
  243. REF_LEXICAL_ERROR    =    3    ; reference of unbound lexical variable
  244. SET_LEXICAL_ERROR    =    4    ; SET! error-- lexical variable not defined
  245. REF_FLUID_ERROR        =    5    ; reference of unbound fluid variable
  246. SET_FLUID_ERROR        =    6    ; SET-FLUID! error-- fluid not bound
  247. VECTOR_OFFSET_ERROR    =    7    ; vector index out of range
  248. STRING_OFFSET_ERROR    =    8    ; string index out of range
  249. SUBSTRING_RANGE_ERROR    =    9    ; invalid substring range
  250. INVALID_OPERAND_ERROR    =    10    ; Invalid operand to VM instruction
  251. SHIFT_BREAK_CONDITION    =    11    ; SHFT-BRK key was depressed by user
  252. NON_PROCEDURE_ERROR    =    12    ; Attempted to call non-procedural object
  253. TIMEOUT_CONDITION    =    13    ; Timer interrupt or Mouse Event
  254. WINDOW_FAULT_CONDITION    =    14    ; Attempt to do I/O to a de-exposed window
  255. FLONUM_OVERFLOW_ERROR    =    15    ; Flonum Over/Under-flow
  256. ZERO_DIVIDE_ERROR    =    16    ; Division by zero
  257. NUMERIC_OPERAND_ERROR    =    17    ; non-numeric operand
  258. APPLY_ARG_LIMIT_ERROR    =    18    ; too many arguments for APPLY to handle
  259. VECTOR_SIZE_LIMIT_ERROR    =    19    ; attempt to allocate vector which is too big
  260. STRING_SIZE_LIMIT_ERROR    =    20    ; attempt to allocate string which is too big
  261. IO_ERRORS_START        =    21    ; Errors between 21 and 84 are DOS I/O errors
  262.  
  263. DOS_FATAL_ERROR        =    21    ; Generic fatal I/O error
  264. EXTEND_START_ERROR_CODE    =    1    ; Extended error codes from INT 59h
  265. EXTEND_END_ERROR_CODE    =    88
  266. DISK_FULL_ERROR        =    200    ; Our own home-grown error codes
  267. LAST_ERROR        =    200    ; Future errors should start here
  268.     
  269. ; Here follow the most useful typedefs, also available in C (lb)
  270.  
  271. STRUC    REG
  272. disp    DW    ?
  273. LABEL    bpage    BYTE
  274. page    DW    ?
  275. ENDS    REG
  276.  
  277. STRUC    POINTER    
  278. page    DB    ?
  279. disp    DW    ?
  280. ENDS    POINTER    
  281.     
  282. STRUC    FIXNUM        
  283. tag    DB    SPECFIX*2
  284. val    DW    ?
  285. ENDS    FIXNUM    
  286.  
  287. ; Generic object (inherited)
  288. STRUC    ANYDEF
  289.     UNION
  290. tag    DB    ?
  291. gc    DB    ?
  292.     ENDS    
  293. len    DW    ?
  294. data    POINTER <>        
  295. ENDS    ANYDEF
  296.  
  297. ; Free cell (!)
  298. STRUC    FREEDEF
  299.     UNION
  300. tag    DB    FREETYPE
  301. gc    DB    ?
  302.     ENDS    
  303. len    DW    ?
  304. ENDS    FREEDEF
  305.  
  306. ; Free linked list cell
  307. STRUC    FREELISTDEF
  308. tag    DB    SPECFREE*2
  309. next    DW    ?            ; pointer to next free cell in page
  310. ENDS    FREELISTDEF
  311.  
  312. ; List Cell
  313. ;    +-------------v-+-------------------------------+
  314. ;    | car page #  |g|    car displacement    |
  315. ;    +-------------^-+-------------------------------+
  316. ;    | cdr page #  |0|    cdr displacement    |
  317. ;    +---------------+-------------------------------+
  318. ; where g = used during garbage collection
  319. STRUC    LISTDEF    
  320.     UNION
  321. car    POINTER    <>
  322. ptr    POINTER <>
  323. gc    DB    ?
  324.     ENDS    
  325. cdr    POINTER <>
  326. ENDS    LISTDEF    
  327.  
  328. ; Bignum
  329. ;    +-------------v-+-------------------------------+
  330. ;    | BIGTYPE     |g|    length in bytes        |
  331. ;    +-------------^-+-------------------------------+
  332. ;    |    sign    |    least significant word    |
  333. ;    +---------------+--------------------------------
  334. ;            :                 :
  335. ;            +-------------------------------+
  336. ;            |    most significant word    |
  337. ;            +-------------------------------+
  338. ; where g = used during garbage collection
  339. STRUC    BIGDATA
  340. len    DW    ?             ; length of entire data structure in bytes
  341. sign    DB    ?             ; sign of the bignum
  342. lsw    DW    ?             ; data bits, with LSBs appearing first
  343. msw    DW    ?             ; second word of significant bits
  344. ENDS    BIGDATA
  345.  
  346. STRUC    BIGDEF
  347.     UNION
  348. tag    DB    BIGTYPE         ; tag = bignum
  349. gc    DB    ?
  350.     ENDS
  351. data    BIGDATA    ?
  352. ENDS    BIGDEF    
  353.  
  354. ; special structure to occupy a vacant slot in a FLONUM page
  355. STRUC    FREEFLODEF
  356. tag    DB    FREETYPE
  357. next    DW    ?            ; pointer to next free cell in page
  358. ENDS    FREEFLODEF
  359.  
  360. ; Flonum
  361. ;    +-------------v-+---+---+---+---+---+---+---+---+
  362. ;    | FLOTYPE     | | 64 bit IEEE floating point    |
  363. ;    +-------------^-+---+---+---+---+---+---+---+---+
  364. ; where g = used during garbage collection
  365. STRUC    FLODEF
  366.     UNION
  367. tag    DB    FLOTYPE         ; tag = flonum
  368. gc    DB    ?
  369.     ENDS        
  370.     UNION
  371. data    DQ    ?
  372. ptr    POINTER    <>
  373.     ENDS        
  374. ENDS    FLODEF    
  375.  
  376. ; Vector (Array)
  377. ;    +-------------v-+-------------------------------+
  378. ;    | VECTTYPE    |g|    length in bytes        |
  379. ;    +-------------^-+-------------------------------+
  380. ;    :        data #i pointer            :
  381. ;    ------------------------------------------------+
  382. ; where g = used during garbage collection
  383. STRUC    VECDEF
  384.     UNION
  385. tag    DB    VECTTYPE
  386. gc    DB    ?
  387.     ENDS        
  388. len    DW    ?
  389. LABEL    data    POINTER
  390. ENDS    VECDEF    
  391.  
  392. ; Symbol
  393. ;    +-------------v-+-------------------------------+
  394. ;    | SYMBTYPE    |g|    length in bytes        |
  395. ;    +-------------^-+-------------------------------+
  396. ;    |        link pointer            |
  397. ;    +-+-------------+---------------v---------------+
  398. ;    | hash value    : characters    :
  399. ;    +---------------+---------------+
  400. ; where g = used during garbage collection
  401. STRUC    SYMDEF
  402.     UNION
  403. tag    DB    SYMBTYPE         ; tag = symbol
  404. gc    DB    ?
  405.     ENDS        
  406. len    DW    ?             ; length of symbol structure in bytes
  407. link    POINTER <>
  408. hashkey DB    ?             ; hash key
  409. LABEL    buffer    BYTE            ; character(s) in symbol
  410. ENDS    SYMDEF    
  411.  
  412. ; String
  413. ;    +-------------v-+-------------------------------+
  414. ;    | STRTYPE     |g|    length in bytes        |
  415. ;    +-------------^-+-------------------------------+
  416. ;    : characters    :
  417. ;    +---------------+
  418. ; where g = used during garbage collection
  419. STRUC    STRDEF
  420.     UNION
  421. tag    DB    STRTYPE            ; tag = string
  422. gc    DB    ?
  423.     ENDS        
  424. len    DW    ?             ; length of string structure in bytes
  425. LABEL    buffer    BYTE            ; character(s) in string
  426. ENDS    STRDEF    
  427.  
  428. MACRO    sstrlen    dest, pntr, ohead
  429.     LOCAL    @@bigstring, @@allstrings
  430.     mov    dest, [(STRDEF pntr).len]
  431.     or    dest, dest
  432.     jge    @@bigstring
  433. IFIDN    <ohead>, <OVERHEAD>
  434.     add    dest, OFFSET (TYPE STRDEF).buffer + SIZE POINTER
  435. @@bigstring:
  436. ELSE
  437.     add    dest, SIZE POINTER
  438.     jmp    @@allstrings
  439. @@bigstring:
  440.     sub    dest, OFFSET (TYPE STRDEF).buffer
  441. @@allstrings:
  442. ENDIF
  443.     ENDM
  444.  
  445. ; Closure
  446. ;    +-------------v-+-------------------------------+
  447. ;    | CLOSTYPE    |g|    length in bytes        |
  448. ;    +-------------^-+-------------------------------+
  449. ;    |     information operand pointer        |
  450. ;    +---------------+-------------------------------+
  451. ;    |    heap environment pointer        |
  452. ;    +---------------+-------------------------------+
  453. ;    |    code block pointer            |
  454. ;    +---------------+-------------------------------+
  455. ;    | SPECFIX*2    | Entry Point Displacement    |
  456. ;    +---------------+-------------------------------+
  457. ;    | SPECFIX*2    | Number of Arguments        |
  458. ;    +---------------+-------------------------------+
  459. ; where g = used during garbage collection
  460. STRUC    CLOSDEF
  461.     UNION
  462. tag    DB    CLOSTYPE         ; tag = closure
  463. gc    DB    ?
  464.     ENDS        
  465. len    DW    ?             ; length of closure object in bytes
  466. info    POINTER <>            ; information operand
  467. heap    POINTER <>            ; heap environment pointer
  468. codeblk    POINTER    <>            ; code base
  469. entry    FIXNUM <>            ; entry point tag = immediate
  470. args    FIXNUM    <>            ; number of arguments tag = immediate
  471. LABEL    debug    BYTE            ; optional debugging information?
  472. ENDS    CLOSDEF    
  473.  
  474. ; Continuation
  475. ;    +-------------v-+-------------------------------+
  476. ;    | CONTTYPE    |g|    length in bytes        |
  477. ;    +-------------^-+-------------------------------+
  478. ;    | SPECFIX*2    | stack base of continuation    |
  479. ;    +---------------+-------------------------------+
  480. ;    |    return address code base pointer    |\
  481. ;    +---------------+-------------------------------+ | return address
  482. ;    | SPECFIX*2    | return address displacement    |/
  483. ;    +---------------+-------------------------------+
  484. ;    | SPECFIX*2    | caller's dynamic link (FP)    |
  485. ;    +---------------+-------------------------------+
  486. ;    |    fluid environment pointer (fnv_reg)    |
  487. ;    +---------------+-------------------------------+
  488. ;    | previous stack segment (continuation) pointer |
  489. ;    +---------------+-------------------------------+
  490. ;    |    global environment pointer (gnv_reg)    |
  491. ;    +---------------+-------------------------------+
  492. ;    :                         :< - BASE
  493. ;    :    [contents of stack at call/cc]        :
  494. ;    :                         :< - topofstack
  495. ;    +-----------------------------------------------+
  496. ; where g = used during garbage collection
  497. STRUC    CONTDEF
  498.     UNION
  499. tag    DB    CONTTYPE         ; tag = continuation
  500. gc    DB    ?
  501.     ENDS        
  502. len    DW    ?             ; length of continuation structure in bytes
  503. base    FIXNUM    <>
  504. codeblk    POINTER    <>            ; return address code base pointer
  505. retaddr    FIXNUM    <>            ; return address displacement
  506. dynlink    FIXNUM    <>            ; caller's dynamic link
  507. fluid    POINTER <>            ; fluid environment pointer
  508. stk    POINTER    <>            ; previous stack segment pointer
  509. globenv    POINTER <>            ; global environment pointer
  510. LABEL    data    BYTE            ; contents of stack at call/cc
  511. ENDS    CONTDEF    
  512.  
  513. ; Code Block
  514. ;    +-------------v-+-------------------------------+
  515. ;    | CODETYPE    |g|    length in bytes        |
  516. ;    +-------------^-+-------------------------------+
  517. ;    | SPECFIX*2    |    entry offset        |-\
  518. ;    +---------------+-------------------------------+ |
  519. ;    :    pointer to constant #i            : |
  520. ;    +---------------+---------------+---------------+ |
  521. ;/----->:    code    :                  |
  522. ;|    +---------------+                  |
  523. ;\--------------------------------------------------------/
  524. ; where g = used during garbage collection
  525. STRUC    CODEDEF
  526.     UNION
  527. tag    DB    CODETYPE         ; tag = code block
  528. gc    DB    ?
  529.     ENDS        
  530. len    DW    ?             ; length of code block in bytes
  531. entry    FIXNUM    <>            ; entry offset tag = fixnum
  532. consts    POINTER    <>            ; code block constants area
  533. ENDS    CODEDEF
  534.  
  535. ; Inline code block
  536. ;    +-------------v-+-------------------------------+
  537. ;    | I86TYPE     |g|    length in bytes        +
  538. ;    +-------------^-+-------------------------------+
  539. ;    : machine code    :
  540. ;    +---------------+
  541. ; where g = used during garbage collection
  542. STRUC    I86DEF
  543.     UNION
  544. tag    DB    I86TYPE
  545. gc    DB    ?
  546.     ENDS
  547. len    DW    ?
  548. LABEL    data    BYTE
  549. ENDS    I86DEF
  550.  
  551. ; Environment Data Object
  552. ;    +-------------v-+-------------------------------+
  553. ;    | ENVTYPE     |g|    length in bytes        |
  554. ;    +-------------^-+-------------------------------+
  555. ;    |         parent pointer            |
  556. ;    +---------------+-------------------------------+
  557. ;    | list of symbols (linked through cdr field)    |
  558. ;    +---------------+-------------------------------+
  559. ;    | list of values (linked through car field)    |
  560. ;    +---------------+-------------------------------+
  561. ; where g = used during garbage collection
  562. STRUC    ENVDEF
  563.     UNION
  564. tag    DB    ENVTYPE         ; tag = environment
  565. gc    DB    ?
  566.     ENDS        
  567. len    DW    ?             ; length in bytes
  568. parent    POINTER <>
  569. names    POINTER    <>            ; list of names
  570. values    POINTER    <>            ; list of values
  571. ENDS    ENVDEF
  572.  
  573. ; Port
  574. ;    +-------------v-+-------------------------------+
  575. ;    | PORTTYPE    |g|    length in bytes        |
  576. ;    +-------------^-+-------------------------------+
  577. ;    |        source pointer            |
  578. ;    +---------------+---------------+---------------+---------------+
  579. ;    |     port flags        |         handle        |
  580. ;    +---------------+---------------+---------------+---------------+
  581. ;    |    cursor line        |    cursor column        |
  582. ;    +---------------+---------------+---------------+---------------+
  583. ;    |    upper left line        |    upper left column    |
  584. ;    +---------------+---------------+---------------+---------------+
  585. ;    |    number of lines        |    number of columns    |
  586. ;    +---------------+---------------+---------------+---------------+
  587. ;    |    border attributes    |    text attributes        |
  588. ;    +---------------+---------------+---------------+---------------+
  589. ;    |    window flags        |    buffer position        |
  590. ;    +---------------+---------------+---------------+---------------+
  591. ;    |    buffer end        : i/o buffer    :
  592. ;    +---------------+---------------+---------------+
  593. ; where g = used during garbage collection
  594. ;
  595. ;        10 9 8 7 6 5 4 3 2 1 0
  596. ;        +-^-^-^-v-v---v---v---+
  597. ; port flags:    |l|t|w|f|m|typ|wrm|rdm|
  598. ;        +-^-^-+-^-^---^---^---+
  599. ;
  600. ; rdm (read mode) :    11    read exclusive
  601. ;            10    read shared
  602. ;            01    read ignored (return #eof)
  603. ;            00    read closed
  604. ; wrm (write mode) :    11    write exclusive
  605. ;            10    write shared
  606. ;            01    write ignored
  607. ;            00    write closed
  608. ; typ (port type) :    11    file (name at source ptr)
  609. ;            10    string (source at source ptr)
  610. ;            01    software (closure at source ptr)
  611. ;            00    window (label at source ptr)
  612. ; m (port mode) :    1    binary
  613. ;            0    text
  614. ; f (flush state) :    1    port was flushed (buffer unchanged)
  615. ;            0    port not flushed (buffer modified)
  616. ; w (wrap mode):    1    wrap
  617. ;             0    clip
  618. ; t (transcript mode):    1    transcript on
  619. ;             0    transcript off
  620. ; l (locking mode):    1    auto-lock on
  621. ;             0    auto-lock off
  622. ;
  623. BUFFSIZE =    100h
  624.  
  625. STRUC    PORTDEF
  626.     UNION
  627. tag    DB    PORTTYPE         ; tag = port
  628. gc    DB    ?
  629.     ENDS        
  630. len    DW    ?             ; length of port structure in bytes
  631. ptr    POINTER    <>
  632. pflags    DW    ?             ; port flags
  633. handle    DW    ?             ; file's handle
  634. curline    DW    ?             ; cursor line number
  635. curcol    DW    ?             ; cursor column number
  636. LABEL    chunk    WORD            ; chunk (buffer #)
  637. ulline    DW    ?             ; upper left hand corner's line number
  638. ulcol    DW    ?             ; upper left hand corner's column number
  639. nlines    DW    ?             ; number of lines
  640. ncols    DW    ?             ; number of columns/line length
  641. border    DW    ?             ; window's border attributes
  642. text    DW    ?             ; window's text attributes
  643. flags    DW    ?             ; window flags
  644. bufpos    DW    ?             ; buffer position (offset)
  645. bufend    DW    ?             ; end of buffer offset
  646. buffer    DB    BUFFSIZE DUP (?)    ; input/output buffer
  647. next    POINTER    <>
  648. ENDS    PORTDEF    
  649.  
  650. W_WRAP        =    00000001b        ; kill these
  651. W_TRANS     =    00000010b        ; kill these
  652.     
  653. PORT_OPEN    =    0000000000001111b
  654. READ_MODE    =    0000000000000011b
  655. READ_OPEN    =    0000000000000010b
  656. WRITE_MODE    =    0000000000001100b
  657. WRITE_OPEN    =    0000000000001000b
  658. PORT_TYPE    =    0000000000110000b
  659. PORT_SHARED    =    0000000000100000b
  660. PORT_BINARY    =    0000000001000000b
  661. PORT_FLUSHED    =    0000000010000000b
  662. PORT_WRAP    =    0000000100000000b
  663. PORT_TRANSCRIPT    =    0000001000000000b
  664. PORT_LOCKED    =    0000010000000000b
  665.  
  666. READ_EXCLUSIVE    =    0000000000000011b
  667. READ_SHARED    =    0000000000000010b
  668. READ_IGNORED    =    0000000000000001b
  669. READ_CLOSED    =    0000000000000000b
  670. WRITE_EXCLUSIVE    =    0000000000001100b
  671. WRITE_SHARED    =    0000000000001000b
  672. WRITE_IGNORED    =    0000000000000100b
  673. WRITE_CLOSED    =    0000000000000000b
  674. TYPE_FILE    =    0000000000110000b
  675. TYPE_STRING    =    0000000000100000b
  676. TYPE_SOFTWARE    =    0000000000010000b
  677. TYPE_WINDOW    =    0000000000000000b
  678.  
  679. IN_PAGE        =    SPECPOR     ; standard input port
  680. IN_DISP        =    0
  681. OUT_PAGE    =    SPECPOR     ; standard output port
  682. OUT_DISP    =    0
  683. WHO_PAGE    =    SPECPOR     ; "who-line"
  684. WHO_DISP    =    SIZE PORTDEF
  685. ; Stack Frame
  686. ;
  687. ;             +------------+--------------------------+
  688. ; Stack base--->|    stack for prev dynamic levels    :
  689. ;        +------------+--------------------------+
  690. ; Frame pointer>|        code base pointer    |
  691. ;        +------------+--------------------------+
  692. ;        |        return address        |
  693. ;        +------------+--------------------------+
  694. ;        |        dynamic link        | caller's FP
  695. ;        +------------+--------------------------+
  696. ;        |        environment        | current environment
  697. ;        +------------+--------------------------+
  698. ;        |        static link        | lexical parent's FP
  699. ;        +------------+--------------------------+
  700. ;        |        closure ptr         | pointer to routine's closure object
  701. ;        +------------+--------------------------+ (or nil, if an open call)
  702. ;        :    local variable pointer        :
  703. ;        +------------+--------------------------+
  704. ; top of stack->|    last local variable        |
  705. ;        +------------+--------------------------+
  706. STRUC    STKFDEF    
  707. codeblk    POINTER    <>             ; code base pointer
  708. retaddr    POINTER    < SPECFIX*2 >         ; return address
  709. dynlink    POINTER    < SPECFIX*2 >        ; dynamic link
  710. heap    POINTER    <>            ; heap environment
  711. statlink    POINTER    < SPECFIX*2 >    ; lex parent's static link
  712. closure    POINTER    <>            ; closure pointer
  713. LABEL    data    POINTER            ; start of local variable allocation area
  714. ENDS    STKFDEF    
  715.  
  716. ;************************************************************************
  717. ;* Here are the global declarations                    *
  718. ;************************************************************************
  719. GLOBAL    C clock:    FAR
  720. GLOBAL    C close:    FAR
  721. GLOBAL    C exit:        FAR
  722. GLOBAL    C free:        FAR
  723. GLOBAL  C heapcheck:    FAR
  724. GLOBAL    C malloc:    FAR
  725. GLOBAL    C realloc:    FAR
  726. GLOBAL    C printf:    FAR
  727. GLOBAL    C sprintf:    FAR
  728. GLOBAL    C strlen:    FAR
  729.  
  730. GLOBAL    @REG@relocate$qv:    FAR
  731. GLOBAL    @REG@check$qv:        FAR
  732. GLOBAL    @REG@cleanup$qp3REGt1:    FAR
  733.  
  734. GLOBAL    alloc_err:    NEAR
  735. GLOBAL    appendb:    NEAR
  736. GLOBAL    apply:        NEAR
  737. GLOBAL    apply_tr:    NEAR
  738. GLOBAL    assoc:        NEAR
  739. GLOBAL    assq:        NEAR
  740. GLOBAL    assv:        NEAR
  741. GLOBAL    bind_fl:    NEAR
  742. GLOBAL    call_cc:    NEAR
  743. GLOBAL    call_clo:    NEAR
  744. GLOBAL    call_ctr:    NEAR
  745. GLOBAL    call_lcl:    NEAR
  746. GLOBAL    call_ltr:    NEAR
  747. GLOBAL    ch_down:    NEAR
  748. GLOBAL    ch_eq_ci:    NEAR
  749. GLOBAL    ch_eq_p:    NEAR
  750. GLOBAL    ch_lt_ci:    NEAR
  751. GLOBAL    ch_lt_p:    NEAR
  752. GLOBAL    ch_up:        NEAR
  753. GLOBAL    clcc_c:        NEAR
  754. GLOBAL    clcc_ctr:    NEAR
  755. GLOBAL    cl_cctr:    NEAR
  756. GLOBAL    cr_close:    NEAR
  757. GLOBAL    debug_op:    NEAR
  758. GLOBAL    define:        NEAR
  759. GLOBAL    def_env:    NEAR
  760. GLOBAL    drop_env:    NEAR
  761. GLOBAL    env_lu:        NEAR
  762. GLOBAL    env_p:        NEAR
  763. GLOBAL    env_par:    NEAR
  764. GLOBAL    execute:    NEAR
  765. GLOBAL    exit_suspend:    NEAR
  766. GLOBAL    fix_big:    NEAR
  767. GLOBAL    fluid_p:    NEAR
  768. GLOBAL    get_num:    NEAR
  769. GLOBAL    get_wind:    NEAR
  770. GLOBAL    graph_attr:    NEAR
  771. GLOBAL    hash_env:    NEAR
  772. GLOBAL    ld_caaar:    NEAR
  773. GLOBAL    ld_caadr:    NEAR
  774. GLOBAL    ld_caar:    NEAR
  775. GLOBAL    ld_cadar:    NEAR
  776. GLOBAL    ld_caddd:    NEAR
  777. GLOBAL    ld_caddr:    NEAR
  778. GLOBAL    ld_cadr:    NEAR
  779. GLOBAL    ld_car:        NEAR
  780. GLOBAL    ld_car1:    NEAR
  781. GLOBAL    ld_cdaar:    NEAR
  782. GLOBAL    ld_cdadr:    NEAR
  783. GLOBAL    ld_cdar:    NEAR
  784. GLOBAL    ld_cddar:    NEAR
  785. GLOBAL    ld_cdddr:    NEAR
  786. GLOBAL    ld_cddr:    NEAR
  787. GLOBAL    ld_cdr:        NEAR
  788. GLOBAL    ld_cdr1:    NEAR
  789. GLOBAL    ld_env:        NEAR
  790. GLOBAL    ld_fluid:    NEAR
  791. GLOBAL    ld_fl_r:    NEAR
  792. GLOBAL    ld_globl:    NEAR
  793. GLOBAL    ld_globr:    NEAR
  794. GLOBAL    ld_lex:        NEAR
  795. GLOBAL    ld_local:    NEAR
  796. GLOBAL    list2:        NEAR
  797. GLOBAL    loadems:    FAR
  798. GLOBAL    lookup:        FAR
  799. GLOBAL    l_tail:        NEAR
  800. GLOBAL    make_str:    NEAR
  801. GLOBAL    make_win:    NEAR
  802. GLOBAL    member:        NEAR
  803. GLOBAL    memq:        NEAR
  804. GLOBAL    memv:        NEAR
  805. GLOBAL    mk_env:        NEAR
  806. GLOBAL    next:        NEAR
  807. GLOBAL    next_pc:    NEAR
  808. GLOBAL    not_yet:    NEAR
  809. GLOBAL    obj_hash:    NEAR
  810. GLOBAL    obj_unhs:    NEAR
  811. GLOBAL    prt_len:    NEAR
  812. GLOBAL    push_env:    NEAR
  813. GLOBAL    rd_ch_rd:    NEAR
  814. GLOBAL    read_cha:    NEAR
  815. GLOBAL    restscr:    FAR
  816. GLOBAL    rest_win:    NEAR
  817. GLOBAL    ret_num:    NEAR
  818. GLOBAL    reverseb:    NEAR
  819. GLOBAL    save_win:    NEAR
  820. GLOBAL    sch_err:    NEAR
  821. GLOBAL    sdrop:        NEAR
  822. GLOBAL    set_car:    NEAR
  823. GLOBAL    set_cdr:    NEAR
  824. GLOBAL    set_gnv:    NEAR
  825. GLOBAL    shft_brk:    FAR
  826. GLOBAL    spnewlin:    NEAR
  827. GLOBAL    spop:        NEAR
  828. GLOBAL    spprinc:    NEAR
  829. GLOBAL    spprint:    NEAR
  830. GLOBAL    spprin1:    NEAR
  831. GLOBAL    spush:        NEAR
  832. GLOBAL    src_err:    NEAR
  833. GLOBAL    srd_atom:    NEAR
  834. GLOBAL    srd_line:    NEAR
  835. GLOBAL    str_apnd:    FAR
  836. GLOBAL    str_fill:    NEAR
  837. GLOBAL    st_env:        NEAR
  838. GLOBAL    st_fluid:    NEAR
  839. GLOBAL    st_globl:    NEAR
  840. GLOBAL    st_lex:        NEAR
  841. GLOBAL    st_local:    NEAR
  842. GLOBAL    st_ref:        NEAR
  843. GLOBAL    st_set:        NEAR
  844. GLOBAL    s_cons:        NEAR
  845. GLOBAL    s_disply:    NEAR
  846. GLOBAL    s_exit:        NEAR
  847. GLOBAL    s_list:        NEAR
  848. GLOBAL    take_fil:    NEAR
  849. GLOBAL    timeout:    NEAR
  850. GLOBAL    trns_chg:    NEAR
  851. GLOBAL    try_big:    NEAR
  852. GLOBAL    unbind_f:    NEAR
  853. GLOBAL    vec_allo:    NEAR
  854. GLOBAL    vec_fill:    NEAR
  855. GLOBAL    vec_size:    NEAR
  856.  
  857. ;************************************************************************
  858. ;*            MMU global data                    *
  859. ;************************************************************************
  860. GLOBAL    defpagesize:    WORD
  861. GLOBAL    pagetable:    WORD:NUMPAGES
  862. GLOBAL    C nextpage:    WORD        ; Next unused page number
  863. GLOBAL    C nextpara:    WORD        ; Next available paragraph number
  864. GLOBAL    C lastpage:    WORD        ; Last unused page number
  865. GLOBAL    C attrib:    WORD:NUMPAGES    ; Page Attribute Table
  866. GLOBAL    C nextcell:    WORD:NUMPAGES    ; Next available location table
  867. GLOBAL    C pagelink:    WORD:NUMPAGES    ; Page link table
  868. GLOBAL    C ptype:    BYTE:NUMPAGES    ; Page type table
  869. GLOBAL    C psize:    WORD:NUMPAGES    ; Page size table
  870. GLOBAL    C pageattr:    WORD:NUMTYPES
  871. GLOBAL    C pagelist:    WORD:NUMTYPES
  872. GLOBAL    C listpage:    WORD        ; [0] Page number for list cell allocation
  873. GLOBAL    C fixpage:    WORD        ; [1] Page number for fixnum allocation
  874. GLOBAL    C flopage:    WORD        ; [2] Page number for flonum allocation
  875. GLOBAL    C bigpage:    WORD        ; [3] Page number for bignum allocation
  876. GLOBAL    C sympage:    WORD        ; [4] Page number for symbol allocation
  877. GLOBAL    C stpage:    WORD        ; [5] Page number for string allocation
  878. GLOBAL    C vectpage:    WORD        ; [6] Page number for vector allocation
  879. GLOBAL    C contpage:    WORD        ; [7] Page number for continuation allocation
  880. GLOBAL    C clospage:    WORD        ; [8] Page number for closure allocation
  881. GLOBAL    C freepage:    WORD        ; [9] Page number for free pages list
  882. GLOBAL    C codepage:    WORD        ; [10] Page number for code page allocation
  883. GLOBAL    C i86page:    WORD        ; [11] Page number for inline code allocation
  884. GLOBAL    C portpage:    WORD        ; [12] Page number for port cell allocation
  885. GLOBAL    C chapage:    WORD        ; [13] Page number for characters
  886. GLOBAL    C envpage:    WORD        ; [14] Page number for environments
  887.  
  888. ;************************************************************************
  889. ;*            Hashing & propertizing                *
  890. ;************************************************************************
  891. GLOBAL    C hash_page:    BYTE:HT_SIZE
  892. GLOBAL    C hash_disp:    WORD:HT_SIZE    ; oblist's hash table
  893. GLOBAL    C obj_hlist:    POINTER        ; object hash table
  894. GLOBAL    C prop_page:    BYTE:HT_SIZE
  895. GLOBAL    C prop_disp:    WORD:HT_SIZE    ; property list hash table
  896.     
  897. ;************************************************************************
  898. ;*                Registers                *
  899. ;************************************************************************
  900. GLOBAL    C cb_reg:    REG
  901. GLOBAL    C console_reg:    REG
  902. GLOBAL    C fnv_reg:    REG
  903. GLOBAL    C fnv_save:    REG
  904. GLOBAL    C gnv_reg:    REG
  905. GLOBAL    C nil_reg:    REG
  906. GLOBAL    C prev_reg:    REG
  907. GLOBAL    C macro_reg:    REG
  908. GLOBAL    C quote_reg:    REG
  909. GLOBAL    C reg0:        REG
  910. GLOBAL    C reg1:        REG
  911. GLOBAL    C regs:        REG:NUM_REGS
  912. GLOBAL    C stl_save:    REG
  913. GLOBAL    C tm2_reg:    REG
  914. GLOBAL    C tm2_adr:    WORD
  915. GLOBAL    C tmp_reg:    REG
  916. GLOBAL    C tmp_adr:    WORD
  917. GLOBAL    C trns_reg:    REG
  918. GLOBAL    C macro_reg:    REG
  919. GLOBAL    C port_reg:    REG
  920. GLOBAL    C nextport_reg:    REG:4
  921. GLOBAL    C s_stack:    STKFDEF        ; The Scheme runtime stack
  922.  
  923. ;************************************************************************
  924. ;*                all global data                *
  925. ;************************************************************************
  926. GLOBAL    C base:        WORD
  927. GLOBAL    C ccount:    WORD
  928. GLOBAL    C curcol:     WORD
  929. GLOBAL    C curline:    WORD
  930. GLOBAL    curs_sav:    WORD
  931. GLOBAL    cur_off:    WORD
  932. GLOBAL    C decpoint:    BYTE
  933. GLOBAL    C pflags:    WORD
  934. GLOBAL    emsbias:    BYTE
  935. GLOBAL    emshandle:    WORD
  936. GLOBAL    C emspages:    BYTE
  937. GLOBAL    C err_ent:    WORD        ; Scheme debugger entry point offset
  938. GLOBAL    firstparagraph:    WORD
  939. GLOBAL    first_dos:    WORD
  940. GLOBAL    C fp_save:    WORD
  941. GLOBAL    C frameptr:    WORD
  942. GLOBAL    C handlee:    WORD
  943. GLOBAL    C hicases:    BYTE
  944. GLOBAL    C history:    BYTE
  945. GLOBAL    C histpos:    WORD
  946. GLOBAL    C histend:    WORD
  947. GLOBAL    C icount:    DWORD:256
  948. GLOBAL    C index:    WORD
  949. GLOBAL    C insert_m:    WORD
  950. GLOBAL    C locases:    BYTE
  951. GLOBAL    mouse_use:    WORD
  952. GLOBAL    C ncols:     WORD
  953. GLOBAL    C nlines:    WORD
  954. GLOBAL    C paragraphnum:    WORD
  955. GLOBAL    C pcsksenv:    WORD        ; char *
  956. GLOBAL    C pcsrsenv:    WORD        ; char *
  957. GLOBAL    C prn_handle:    WORD
  958. GLOBAL    C rst_ent:    WORD        ; Scheme-reset state variables
  959. GLOBAL    C show:        BYTE
  960. GLOBAL    C spchars:    WORD
  961. GLOBAL    C stk_in:    DWORD
  962. GLOBAL    C stk_out:    DWORD
  963. GLOBAL    C str_p:    WORD
  964. GLOBAL    C s_break:    BYTE        ; flag indicating shift-break key depressed
  965. GLOBAL    C s_pc:        WORD
  966. GLOBAL    tickstat:    BYTE
  967. GLOBAL    C topofstack:    WORD
  968. GLOBAL    C t_attrib:    WORD
  969. GLOBAL    C ulcol:    WORD
  970. GLOBAL    C ulline:    WORD
  971. GLOBAL    C vidmode:    WORD
  972. GLOBAL    C vm_debug:    WORD        ; flag indicating VM debug mode
  973. GLOBAL    C win_p:    WORD
  974.  
  975. ;************************************************************************
  976. ;*            Flags & macros                    *
  977. ;************************************************************************
  978. ; Flags put in [show] for sprint
  979. SP_SEPARE = 01h
  980. SP_OUTPUT = 02h
  981.  
  982. ; this special page value means we deal with an EMS page not currently loaded.
  983. EMSPAGE = 1
  984.  
  985. ; The LoadPage macros should be used to obtain the address of a given page
  986. ; from the pagetable. This must be done in order to access any given heap
  987. ; allocated object. For conventional memory, this just means indexing into
  988. ; the pagetable and accessing the paragraph address.
  989.  
  990. MACRO     ldpage    dst, src:REST        ; Get Page address from page table
  991.     local    @@notems
  992. IFDIF    <src>, <bx>
  993. IFDIF    <dst>, <bx>
  994.     push    bx
  995. ENDIF
  996.     mov    bx, src
  997. ENDIF
  998.     cmp    bl, [ss:emsbias]
  999.     jb    @@notems
  1000.     call    loadems
  1001. @@notems:
  1002.     mov    dst, [ss:pagetable+bx]
  1003. IFDIF    <src>, <bx>
  1004. IFDIF    <dst>, <bx>
  1005.     pop    bx
  1006. ENDIF
  1007. ENDIF
  1008. ENDM
  1009.  
  1010. ;************************************************************************
  1011. ;* Now follows the automatically produced code                *
  1012. ;************************************************************************
  1013. MACRO    File    args
  1014.     ENDM
  1015.